<?php
include_once '../../__global.php';
define(TYPE_SUGGEST, 'type_suggest');
define(TYPE_DEFAULT, 'type_latest');

class aj_getSuggestAt extends ml_controller {
    private $key;
    private $uid;
    private $type = TYPE_DEFAULT;
    
    function initParam(){
        
        $this->key = $this->input('key', '', '');
        //$this->uid = $this->__visitor['uid'];
        $this->uid = $this->input('uid', '', '');
        if (empty($this->uid)) {
            $this->uid = $this->__visitor['uid'];;
        }
    }
    
    function checkParam(){
            
        if (!empty($this->key)) {
            $this->type = TYPE_SUGGEST;
        }
    }
    
    function main(){
        
        $data = array();
        $raw = call_user_func(array($this, $this->type));
        foreach ($raw as $uid=>$nick) {
            $data[] = array('uid' => $uid, 'screen_name' => $nick);
        } 
        $data = array_slice($data, 0, 10);   
        $this->api_output(ML_RCODE_SUCC, $data);
    }
    
    function type_suggest(){
        
        $a = new ml_biz_atNick_suggestNick();
        $this->key = strtolower($this->key);
        return $a->get_suggest_nick_by_followlist($this->key, $this->uid);

    }
    
    function type_latest(){
        
        $a = new ml_biz_atNick_followList();
        return $a->get_latestAt_redis($this->uid);
    }
}

new aj_getSuggestAt();